package com.twu.biblioteca;

public class Book {

    private String title;
    private String author;
    private String availability;

    public Book(String title, String author, String availability) {
        this.title = title;
        this.author = author;
        this.availability = availability;
    }

    public static void printTableHeading() {
        StringHandler.printBookHeader();
    }

    public static void reserve(Book book) {
        String reservationSuccessfulMessage = "Thank you! Enjoy the book.\n";
        String bookNotAvailableMessage = "Sorry we don't have that book yet.\n";

        if (checkIfAvailable(book)) {
            StringHandler.printlnMessage(reservationSuccessfulMessage);
            book.setAvailability("reserved");
        } else {
            StringHandler.printlnMessage(bookNotAvailableMessage);
        }
    }

    public static boolean checkIfAvailable(Book book) {
        if (book.getAvailability().equals("available")) return true;
        return false;
    }

    public String getTitle() {
        return title;
    }

    public String getAuthor() {
        return author;
    }

    public String getAvailability() {
        return availability;
    }

    public void setAvailability(String availability) {
        this.availability = availability;
    }

    public void print(int index, Book book) {
        StringHandler.printBook(index, book.getTitle(), book.getAuthor(), book.getAvailability());
    }

    public void print(Book book) {
        StringHandler.printBook(BibliotecaApp.getBookShelf().indexOf(book) + 1, book.getTitle(), book.getAuthor(), book.getAvailability());
    }
}
